package com.xflib.framework.util;

import cn.hutool.core.util.StrUtil;
import com.github.lalyos.jfiglet.FigletFont;
import org.slf4j.Logger;

import java.io.IOException;
import java.io.PrintStream;

/**
 * This is {@link AsciiArtUtils}.
 *
 * @author Misagh Moayyed
 * @since 5.0.0
 */
public class AsciiArtUtils {
    private static final String ANSI_RESET = "\u001B[0m";
    private static final String ANSI_CYAN = "\u001B[36m";

    private AsciiArtUtils(){}
    /**
     * Print ascii art.
     *
     * @param out      the out
     * @param asciiArt the ascii art
     */
    public static void printAsciiArt(final PrintStream out, final String asciiArt) {
        printAsciiArt(out, asciiArt, null);
    }

    /**
     * Print ascii art.
     *
     * @param out        the out
     * @param asciiArt   the ascii art
     * @param additional the additional
     */
    // @SneakyThrows
    public static void printAsciiArt(final PrintStream out, final String asciiArt, final String additional) {
        out.println(ANSI_CYAN);
        try {
            if (StrUtil.isNotBlank(additional)) {
                out.println(FigletFont.convertOneLine(asciiArt));
                out.println(additional);
            } else {
                out.print(FigletFont.convertOneLine(asciiArt));
            }
            out.println(ANSI_RESET);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Print ascii art.
     *
     * @param out        the out
     * @param asciiArt   the ascii art
     * @param additional the additional
     */
    // @SneakyThrows
    public static void printAsciiArtWarning(final Logger out, final String asciiArt, final String additional) {
        out.warn(ANSI_CYAN);
        try {
            String x="\n\n".concat(FigletFont.convertOneLine(asciiArt)).concat(additional);
            out.warn(x);
        } catch (IOException e) {
            e.printStackTrace();
        }
        out.warn(ANSI_RESET);
    }

    /**
     * Print ascii art info.
     *
     * @param out        the out
     * @param asciiArt   the ascii art
     * @param additional the additional
     */
    public static void printAsciiArtInfo(final Logger out, final String asciiArt, final String additional) {
        out.info(ANSI_CYAN);
        try {
            String x="\n\n".concat(FigletFont.convertOneLine(asciiArt)).concat(additional);
            out.info(x);
        } catch (IOException e) {
            e.printStackTrace();
        }
        out.info(ANSI_RESET);
    }

}
